require.config({
    paths: {
        'domReady': 'src/lib/require/domReady',
        'text': 'src/lib/require/text',
        'css': 'src/lib/require/require-css',

        //TODO: 为了兼容hr-manager的前端模型
        'app': '.',
        'config': 'src/config/hack',

        //jquery第三方
        'jquery': 'src/lib/jquery/jquery',
        'jquery.cookie': 'src/lib/jquery/jquery.cookie',
        'jquery.crypto.core': 'src/lib/crypto/core',
        'jquery.crypto.enc.base64': 'src/lib/crypto/enc-base64',
        'dialog': 'src/lib/artDialog/dialog-plus',
        'perfect.scrollbar.jquery': 'src/lib/perfect-scrollbar/js/perfect-scrollbar.jquery',
        'placeholder': 'src/lib/placeholder/jquery.placeholder.min',
        'moment': 'src/lib/moment/moment',
        'moment.zh-cn': 'src/lib/moment/zh-cn',
        'datetimepicker': 'src/lib/datetimepicker/jquery.datetimepicker.full',
        'eChart': 'src/lib/echart/echarts',

        //knockout第三方
        'knockout': 'src/lib/knockout/knockout',
        'knockout.mapping': 'src/lib/knockout/knockout.mapping',
        'knockout.validation': 'src/lib/knockout/knockout.validation',
        'knockout.validation.zh-CN': 'src/lib/knockout/zh-CN',
        'knockout.amd': 'src/lib/knockout/knockout-amd-helpers',

        //慧瑞第三方
        'hr.common': 'src/hr/hr.common',
        'ko.common': 'src/hr/ko.common',
        'mainConfig': 'src/config/mainConfig',
        'autoConfig': 'src/config/autoConfig'
    },
    shim: {
        'jquery.crypto.enc.base64': {
            deps: ['jquery', 'jquery.cookie', 'jquery.crypto.core']
        },
        'dialog': {
            deps: ['jquery']
        },
        'knockout.mapping': {
            deps: ['knockout']
        },
        'ko.common': {
            deps: ['knockout', 'knockout.amd']
        },
        'knockout.validation': {
            deps: ['knockout']
        },
        'knockout.amd': {
            deps: ['text', 'knockout']
        },
        'perfect.scrollbar.jquery': {
            deps: ['jquery']
        },
        'placeholder': {
            deps: ['jquery']
        },
        'jquery.moment': {
            deps: ['jquery']
        },
        'datetimepicker': {
            deps: ['jquery']
        },
        'eChart': {
            deps: ['jquery']
        }
    },
    deps: ['knockout', 'knockout.mapping'], callback: function (ko, koMapping) {
        ko.mapping = koMapping;
    }
});

define('app', function (require) {
    window.ko = require('knockout');
    window.dialog = require('dialog');
    window.moment = require('moment');
    window.mainConfig = require('mainConfig');
    window.autoConfig = require('autoConfig');
    require('jquery');
    require('knockout.mapping');
    require('knockout.validation');
    require('knockout.amd');

    require('jquery.crypto.enc.base64');
    require('knockout.validation.zh-CN');
    require('perfect.scrollbar.jquery');
    require('placeholder');
    require('ko.common');
    require('datetimepicker');

    //设置datatimepicker语言
    $.datetimepicker.setLocale('ch');

    // 配置项
    ko.validation.init({
        registerExtenders: true,
        messagesOnModified: true,
        insertMessages: true,
        decorateInputElement: true,
        errorElementClass: 'u-input-false'
    }, true);

    ko.validation.locale('zh-CN');

    ko.amdTemplateEngine.defaultPath = "/";
});


define('main', ['app'], function (app) {
    document.title = autoConfig.webTitle;

    var uaMatch = navigator.userAgent.toLowerCase().match(/MicroMessenger/i);
    var isWechat = $.isArray(uaMatch) && uaMatch.length > 0;

    var indexUrl = mainConfig.indexUrl;
    if (isWechat) {
        indexUrl = 'src/app/wxIndex/wxIndex';
    }

    var vm = {
        indexPage: ko.observable(indexUrl),
        initPage: ko.observable(),   //TODO: 为了兼容
        currentMenu: ko.observable()   //TODO: 为了兼容
    };
    //TODO: 为了兼容
    vm.initPage.subscribe(function (newValue) {
        vm.indexPage(newValue);
    });
    //-------以上为了兼容--------

    ko.applyBindings(vm);
    return vm;
});

require(['domReady!', 'main']);